<template>
<el-cascader ref="cascaderRef" v-model="selectVal" :options="tree" :props="{
    label: 'label',
    value: 'id',
    emitPath: false,
    checkStrictly: checkStrictly
    }" clearable @change="changeEvt"></el-cascader>
</template>

<script>
import {
    getDepartmentTreeApi,
} from "@/api/ucenter/department";

export default {
    name: "SourcePickerView",
    data() {
        return {
            tree: [],
            selectVal: "",
        };
    },
    props: {
        value: {
            type: [Array, String, Number],
            default: function () {
                return [];
            },
        },
        type: {
            type: String,
            default: "",
        },
        placeholder: {
            type: String,
            default: "请选择",
        },
        checkStrictly: {
            type: Boolean,
            default: false,
        },
    },
    watch: {
        value: {
            immediate: true,
            handler(val) {
                this.selectVal = val;
            }
        },
        type: {
            immediate: true,
            handler(value) {
                getDepartmentTreeApi({}).then((res) => {
                    this.tree = res.data.tree;
                });
            },
        },
    },
    methods: {
        changeEvt() {
            this.$emit("input", this.selectVal);
        },
        clearCascader() {
            this.$nextTick(() => {
                this.selectVal = "";
            });
        }
    },
};
</script>
